# -*- coding: utf-8 -*-

from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

from ib.ext.Contract import Contract
from sqlalchemy import Column, DateTime, String, BigInteger, Float, Integer

class ContractAdapter(Base):
    __tablename__ = 'contracts'
    
    id               = Column(BigInteger, primary_key=True)
    symbol           = Column(String )
    sectype          = Column(String )
    expiry           = Column(String )
    strike           = Column(Float  )
    right            = Column(String )
    multiplier       = Column(Float  )
    exchange         = Column(String )
    currency         = Column(String )
    localsymbol      = Column(String )
    primaryexch      = Column(String )
    includeexpired   = Column(Integer)
    combolegsdescrip = Column(String )
    combolegs        = Column(String )
    undercomp        = Column(String )
    
    
    def Contract(self):
    	contract                    = Contract()
    	contract.m_conId            = str  (self.id              )
    	contract.m_symbol           = str  (self.symbol          )
    	contract.m_secType          = str  (self.sectype         )
    	contract.m_expiry           = str  (self.expiry          )
    	contract.m_strike           = float(self.strike          )
    	contract.m_right            = str  (self.right           )
    	#contract.m_multiplier       = str  (self.multiplier      )
    	contract.m_exchange         = str  (self.exchange        )
    	contract.m_currency         = str  (self.currency        )
    	#contract.m_localSymbol      = str  (self.localsymbol     )
    	#contract.m_primaryExch      = str  (self.primaryexch     )
    	#contract.m_includeExpired   = str  (self.includeexpired  )
    	#contract.m_comboLegsDescrip = str  (self.combolegsdescrip)
    	#contract.m_comboLegs        = str  (self.combolegs       )
    	#contract.m_underComp        = str  (self.undercomp       )
    	
        return contract
    
    
    def __repr__(self):
        return "<ContractAdaper(symbol='%s', sectype='%s', expiry='%s', exchange='%s')>" % (self.symbol, self.sectype, self.expiry, self.exchange)

